<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title> {$action} | {:get_opinion('title')}</title>
    <include file="Public:head"/>
    <link href="__PUBLIC__/AdminLTE/css/timepicker/jquery-ui-1.8.17.custom.css" rel="stylesheet"/>
    <link href="__PUBLIC__/AdminLTE/css/timepicker/jquery-ui-timepicker-addon.css" rel="stylesheet"/>
    <link href="__PUBLIC__/AdminLTE/css/select2/select2.css" rel="stylesheet"/>
    <script type="text/javascript">
        window.UEDITOR_HOME_URL = "__ROOT__/Extend/Ueditor/";
        var post_id = '{$post_id}';
        var URL_upload = "{$URL_upload}";
        var URL_fileUp = "{$URL_fileUp}";
        var URL_scrawlUp = "{$URL_scrawlUp}";
        var URL_getRemoteImage = "{$URL_getRemoteImage}";
        var URL_imageManager = "{$URL_imageManager}";
        var URL_imageUp = "{$URL_imageUp}";
        var URL_getMovie = "{$URL_getMovie}";
        var URL_home = "{$URL_home}";
    </script>
    <style>
        .form-group .controls {
            margin-left: 80px;
        }

        .form-group .control-label {
            width: 60px;
        }

        p {
            text-indent: 28px;
        }
    </style>
    <load href="__ROOT__/Extend/Ueditor/ueditor.config.js"/>
    <load href="__ROOT__/Extend/Ueditor/ueditor.all.js"/>
</head>
<body class="skin-blue">
{:W('Common/header')}
<div class="wrapper row-offcanvas row-offcanvas-left">
    {:W('Common/sideMenu')}
    <!-- Right side column. Contains the navbar and content of the page -->
    <aside class="right-side">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                {$action}
                <small>{:get_opinion('title')}</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="{$module_url}"><i class="fa fa-dashboard"></i> {$module}</a></li>
                <li class="active">{$action}</li>
            </ol>
        </section>
        <!-- Main content -->
        <section class="content">
            <div class="row">
                <form action="{$handle}" id="add_post"
                      name="add_post" class="form-horizontal">
                    <div class="col-md-9">
                        <!-- /.box-header -->
                        <div class="box-body">
                            <div class="form-group">
                                <label class="control-label">标题</label>

                                <div class="controls">
                                    <input type="text" id="post_title"
                                           class="form-control large" name="post_title"
                                           value="{$info.post_title}"/>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="control-label">内容</label>

                                <div class="controls">
                                    <textarea class="span12 ckeditor" id="post_content" name="post_content" title="">{$info.post_content}</textarea>
                                </div>
                            </div>
                            <input type="hidden" name="post_id" value="{$post_id}"/>
                            <hr/>
                            <div class="form-actions" style="  margin-left: 65px;">
                                <button type="button" class="btn btn-info post_save_ctl">
                                    <i class="icon-ok"></i> 保存
                                </button>
                                <control access="Admin/Posts/NOVERIFY">
                                    <button type="button" id="post_submit_ctl" class="btn btn-success submit">
                                        <i class="icon-ok"></i> 立即发布
                                    </button>
                                </control>
                                <span style="font-size: 18px; color: red; font-weight: bold;" id="success"></span>
                            </div>
                        </div>
                    </div>
                    <div class="col-md-3">
                        <div class="box-body well">
                            <div id="post_advance" style="padding-left: 5%">
                                <div class="form-group">
                                    <label class="control-label">状态</label>

                                    <div class="controls">
                                        <select class="small form-control" tabindex="1" name="post_status"
                                                id="post_status">
                                            {$post_status}
                                        </select>
                                        <span class="help-inline">
                                             <button type="button" class="btn btn-info post_save_ctl">
                                                 <i class="icon-ok"></i> 确定
                                             </button>
                                        </span>
                                    </div>
                                </div>
                                <hr/>
                                <div class="form-group">
                                    <label class="control-label">类型</label>

                                    <div class="controls">
                                        <select class="small form-control" tabindex="1" name="post_type" id="post_type">
                                            {$post_type}
                                        </select>
                                        <span class="help-inline"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label">模板</label>

                                    <div class="controls">
                                        <select class="small form-control" tabindex="1" name="post_template"
                                                id="post_template">
                                            {$tpl_type}
                                        </select>
                                        <span class="help-inline"></span>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="control-label">置顶</label>

                                    <div class="controls">
                                        <label class="radio">
                                            <div class="radio">
                                                <if condition="$info.post_top eq 1 ">
									<span class="checked"><input type="radio"
                                                                 name="post_top" value="1" checked=""></span>
                                                    <else/>
									<span class=""><input type="radio"
                                                          name="post_top" value="1"></span>
                                                </if>
                                            </div>
                                            是
                                        </label>
                                        <label class="radio">
                                            <div class="radio">
                                                <if condition="$info.post_top eq 0 ">
										<span class="checked"><input type="radio"
                                                                     name="post_top" value="0" checked=""></span>
                                                    <else/>
										<span class=""><input type="radio"
                                                              name="post_top" value="0"></span>
                                                </if>
                                            </div>
                                            否
                                        </label>
                                    </div>
                                </div>
                                <hr/>
                                <div class="form-group">
                                    <label class="control-label">发布时间:</label>

                                    <div class="input-group controls " style="width: 60%">
                                        <input name="post_date" type="text" class="form-control timepicker"
                                               style="z-index:2"
                                               value="{$info.post_date}"/>

                                        <div class="input-group-addon">
                                            <i class="fa fa-clock-o"></i>
                                        </div>
                                    </div>
                                    <!-- /.input group -->
                                </div>
                                <div class="form-group">
                                <label class="control-label">修改时间:</label>

                                <div class="input-group controls " style="width: 60%">
                                    <input name="post_modified" type="text" class="form-control timepicker"
                                           style="z-index:2" readonly="readonly"
                                           value="{$info.post_modified}"/>

                                    <div class="input-group-addon">
                                        <i class="fa fa-clock-o"></i>
                                    </div>
                                </div>
                            </div>
                                <hr/>
                                <div class="form-group">
                                    <label class="control-label">分类</label>

                                    <div class="controls">
                                        <div class=""
                                             style="width:90% ;height: 300px;overflow: scroll">
                                            <foreach name="cats" item="vCats">
                                                <div><label><input
                                                        type="checkbox" value="{$vCats.cat_id}" name="cats[]"
                                                    <foreach name="info['post_cat']" item="pcs">
                                                        <if condition="$vCats['cat_id'] eq $pcs['cat_id']">
                                                            checked="checked"
                                                            <else/>
                                                        </if>
                                                    </foreach>
                                                    /> {$vCats.cat_slug}
                                                </label>
                                                </div>
                                            </foreach>
                                        </div>
                                    </div>
                                </div>
                                <control access="Admin/Posts/NOVERIFY">
                                    <div class="form-group">
                                        <label class="control-label">标签</label>

                                        <div class="controls">
                                            <select class="js-example-tags js-example-basic-multiple form-control select2-hidden-accessible"
                                                    id="tags" multiple="multiple" name="tags[]" tabindex="-1"
                                                    aria-hidden="true">
                                                <foreach name="tags" item="vTags" key="k">
                                                    <option value="{$vTags.tag_name}"
                                                    <foreach name="info['post_tag']" item="pts">
                                                        <if condition="$vTags['tag_id'] eq $pts['tag_id']">
                                                            selected="selected"
                                                            <else/>
                                                        </if>
                                                    </foreach>
                                                    >{$vTags.tag_name}</option>
                                                </foreach>
                                            </select>
                                        </div>
                                    </div>
                                </control>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </section>
        <!-- /.content -->
    </aside>
    <!-- /.right-side -->
</div>
<!-- ./wrapper -->
<include file="Public:foot"/>
<script type="text/javascript" src="__PUBLIC__/share/js/functions.js"></script>
<script type="text/javascript" src="__PUBLIC__/share/js/jquery.form.js"></script>
<script type="text/javascript" src="__PUBLIC__/share/js/jquery-ui-1.10.4.min.js"></script>
<!--<script type="text/javascript" src="__PUBLIC__/share/js/jquery-ui-1.8.18.min.js"></script>-->
<script type="text/javascript"
        src="__PUBLIC__/AdminLTE/js/plugins/timepicker/jquery-ui-timepicker-addon.js"></script>
<script type="text/javascript"
        src="__PUBLIC__/AdminLTE/js/plugins/timepicker/jquery-ui-timepicker-zh-CN.js"></script>
<script type="text/javascript"
        src="__PUBLIC__/AdminLTE/js/plugins/select2/select2.js"></script>
<script type="text/javascript">
    var editor;
    $(function () {
        //具体参数配置在  editor_config.js  中
        var options = {
            zIndex: 999,
            initialFrameWidth: "100%", //初化宽度
            initialFrameHeight: 400, //初化高度
            focus: false, //初始化时，是否让编辑器获得焦点true或false
            maximumWords: 99999, removeFormatAttributes: 'class,style,lang,width,height,align,hspace,valign'
            , //允许的最大字符数 'fullscreen',
            pasteplain: true, autoHeightEnabled: true,
            autotypeset: {
                mergeEmptyline: true,         //合并空行
                removeClass: true,           //去掉冗余的class
                removeEmptyline: false,      //去掉空行
                textAlign: "left",           //段落的排版方式，可以是 left,right,center,justify 去掉这个属性表示不执行排版
                imageBlockLine: 'center',      //图片的浮动方式，独占一行剧中,左右浮动，默认: center,left,right,none 去掉这个属性表示不执行排版
                pasteFilter: false,            //根据规则过滤没事粘贴进来的内容
                clearFontSize: false,          //去掉所有的内嵌字号，使用编辑器默认的字号
                clearFontFamily: false,        //去掉所有的内嵌字体，使用编辑器默认的字体
                removeEmptyNode: false,       // 去掉空节点
                                              //可以去掉的标签
                removeTagNames: {"font": 1},
                indent: false,                 // 行首缩进
                indentValue: '0em'             //行首缩进的大小
            },
            toolbars: [
                ['fullscreen', 'source', '|', 'undo', 'redo',
                    '|', 'bold', 'italic', 'underline', 'fontborder',
                    'strikethrough', 'superscript', 'subscript',
                    'removeformat', 'formatmatch', 'autotypeset',
                    'blockquote', 'pasteplain', '|', 'forecolor',
                    'backcolor', 'insertorderedlist',
                    'insertunorderedlist', 'selectall', 'cleardoc', '|',
                    'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
                    'customstyle', 'paragraph', 'fontfamily', 'fontsize',
                    '|', 'directionalityltr', 'directionalityrtl',
                    'indent', '|', 'justifyleft', 'justifycenter',
                    'justifyright', 'justifyjustify', '|', 'touppercase',
                    'tolowercase', '|', 'link', 'unlink', 'anchor', '|',
                    'imagenone', 'imageleft', 'imageright', 'imagecenter',
                    '|', 'insertimage', 'emotion', 'insertvideo',
                    'attachment', 'map', 'gmap', 'insertframe',
                    'insertcode', 'webapp', 'pagebreak', 'template',
                    'background', '|', 'horizontal', 'date', 'time',
                    'spechars', 'wordimage', '|',
                    'inserttable', 'deletetable',
                    'insertparagraphbeforetable', 'insertrow', 'deleterow',
                    'insertcol', 'deletecol', 'mergecells', 'mergeright',
                    'mergedown', 'splittocells', 'splittorows',
                    'splittocols', '|', 'print', 'preview', 'searchreplace']
            ]
        };
        editor = new UE.ui.Editor(options);
        editor.render("post_content");
        /*editor.ready(function(){
         editor.setContent('{$v.content}');
         });*/
        $(".submit").click(
                function () {
                    if (editor.hasContents()) {
                        editor.sync();
                    }
                    var div = $("#success");
                    if ($("#post_title").val() == '' ||
                            $("#post_title").val() == '未命名' ||
                            $("#post_content").val() == '') {
                        div.fadeIn().html("标题或内容不能为空");
                        alert('标题或内容不能为空');
                        div.fadeOut(5000);
                        return false;
                    }
                    var arr = [];
                    $("input[name='cats[]']:checked").each(function (i, o) {
//                        a[i] = $(o).val();
                        arr.push($(o).val());
                    });
                    if (arr.length == 0) {
                        div.fadeIn().html("分类信息不能为空<br />请选择分类");
                        alert("分类信息不能为空,请选择分类");
                        div.fadeOut(5000);
                        return false;
                    }
                    var url = '{$handle}';
                    var formObj = $("#add_post");
                    formObj.ajaxSubmit({
                        url: url,
                        type: "POST",
                        dataType: "json",
                        success: function (data) {
                            $(window).unbind('beforeunload', leave_confirm);
                            if (data.status == 1) {
                                $(".submit").hide();
                                div.fadeIn().html(data.info);
                                div.fadeOut(5000);
                            } else {
                                div.fadeIn().html(data.info);
                                div.fadeOut(5000);
                            }
                            if (data.url && data.url != '') {
                                setTimeout(function () {
                                    top.window.location.href = data.url;
                                }, 2000);
                            }
                            if (data.url == '') {
                                setTimeout(function () {
                                    top.window.location.reload();
                                }, 2000);
                            }
                        }
                    });
                });
        $(".timepicker").datetimepicker({
            //showOn: "button",
            //buttonImage: "./css/images/icon_calendar.gif",
            //buttonImageOnly: true,
            showSecond: true,
            timeFormat: 'hh:mm:ss',
            stepHour: 1,
            stepMinute: 1,
            stepSecond: 1
        });
    });
    function leave_confirm() {
        update();
    }
    function update() {
        if (editor.hasContents()) {
            editor.sync();
        }
        var div = $("#success");
        var url = '{$handle}';
        var formObj = $("#add_post");
        if ($("#post_title").val() == '' ||
                $("#post_title").val() == '未命名' ||
                $("#post_content").val() == '') {
            div.fadeIn().html("标题或内容不能为空，不能自动保存");
            div.fadeOut(5000);
            return false;
        }
        formObj.ajaxSubmit({
            url: url,
            type: "POST",
            dataType: "json",
            success: function (data) {
                if (data.status == 1) {
                    div.fadeIn().html("草稿自动保存成功");
                    div.fadeOut(5000);
                } else {
                    div.fadeIn().html("草稿保存失败");
                    div.fadeOut(5000);
                }
                if (data.url && data.url != '') {
                }
                if (data.url == '') {
                }
            }
        })
    }
    function auto_save() {
//        var post_status_dom = $("#post_status");
//        var post_status = post_status_dom.val();
//        post_status_dom.val("draft");
//        post_status_dom.find("option").attr("selected", false);
//        post_status_dom.find("option[value='draft']").attr("selected", true);
        update();
//        post_status_dom.find("option").attr("selected", false);
//        post_status_dom.find("option[value='" + post_status + "']").attr("selected", true);
//        post_status_dom.val(post_status);
    }
    $(window).bind('beforeunload', leave_confirm);
    $(document).ready(function () {
        window.setInterval(auto_save, 60000);
        $(".js-example-tags").select2({
            tags: true
        });
        $("#post_vertify_ctl").click(function () {
            $("#post_status").val("");
            $("#post_status").val("publish");
            $("#post_status").find("option[value='unverified']").attr("selected", false);
            $("#post_status").find("option[value='reverify']").attr("selected", false);
            $("#post_status").find("option[value='draft']").attr("selected", false);
            $("#post_status").find("option[value='publish']").attr("selected", true);
            $('#post_submit_ctl').click();
        });
        $(".post_save_ctl").click(function () {
            auto_save();
        });
    });
</script>
</body>
</html>